package org.example;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

public class Swing2_1 {
    public static void main() throws IOException {
        UserDaoImpl userDao = new UserDaoImpl();
        JFrame jFrame = new JFrame("四川师范大学学生管理系统");//创建窗口
        jFrame.setSize(600,350);//设置窗口大小
        InputStream im = Demo2.class.getClassLoader().getResourceAsStream("1.png");
        BufferedImage image = ImageIO.read(im);
        jFrame.setIconImage(image);
        jFrame.setLocationRelativeTo(null);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Font font = new Font("楷体", Font.PLAIN, 20);

        //对于表格  java不知道数据库里面有多少数据  他只能去做一个滚动条出来
        //按钮:save
        JButton save_t = new JButton("添加信息");
        save_t.setFont(font);
        JButton save_s = new JButton("删除信息");
        save_s.setFont(font);

        Vector<String> vector = new Vector<String>();
        vector.add("学号");
        vector.add("姓名");
        vector.add("成绩");
        vector.add("国籍");
        vector.add("性别");
        vector.add("入学时间");
        JTable jTable = new JTable();

        Vector<Vector<Object>> data =userDao.getStudentAll();
        JTable jTable1 = new JTable(data,vector);
        JScrollPane pane = new JScrollPane(jTable1);
        jFrame.add(pane);
        jFrame.setVisible(true);

        SpringLayout layout = new SpringLayout();
        JPanel center = new JPanel(layout);
        //save1的位置布局
        layout.putConstraint(SpringLayout.WEST, save_t, -30, SpringLayout.WEST, labelUser);
        layout.putConstraint(SpringLayout.NORTH, save_t, userPassH + 30 + 70, SpringLayout.NORTH, labelUser);
        //save2的位置布局
        layout.putConstraint(SpringLayout.EAST, save_s, +30, SpringLayout.EAST, password);
        layout.putConstraint(SpringLayout.NORTH, save_s, userPassH + 30 + 70, SpringLayout.NORTH, labelUser);

        save_s.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jFrame.setVisible(false);
                    try {
                        Swing_del.main();
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
            }
        });
    }
}
